﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class DrawFunction : MonoBehaviour {
	public GameObject pointPrefab;
	public GameObject point;
	public List<GameObject> pointList;
	public float pointsSpeed;

	public float axisInterval;
	public float axisSize;

	public float funcInterval;

	// Start is called before the first frame update
	void Start() {
		//point = Instantiate(pointPrefab, Vector3.zero, Quaternion.identity);
		//points.GetComponent<Point>().aimPos = Vector3.one;
		//points.GetComponent<Point>().speed = pointsSpeed;
		CreateAxis();
		DrawFunction1();
	}

	// Update is called once per frame
	void Update() {

	}

	public void DrawFunction1() {
		for (int i = 0; i * funcInterval < Mathf.PI * 0.5f; i++) {
			float x = i * funcInterval;
			float y = Mathf.Cos(x);
			AddPoint(new Vector3(x, y), 0.05f, Color.yellow);
		}
		for (int i = -1; i * funcInterval > -Mathf.PI * 0.5f; i--) {
			float x = i * funcInterval;
			float y = Mathf.Cos(x);
			AddPoint(new Vector3(x, y), 0.05f, Color.yellow);
		}
	}

	public void CreateAxis() {
		AddPoint(Vector3.zero);
		for (int i = 1; i * axisInterval < axisSize; i++) {
			AddPoint(new Vector3(i * axisInterval, 0));
			AddPoint(new Vector3(-i * axisInterval, 0));
			AddPoint(new Vector3(0, i * axisInterval));
			AddPoint(new Vector3(0, -i * axisInterval));
		}
	}

	private void AddPoint(Vector3 vector3) {
		point = Instantiate(pointPrefab, vector3, Quaternion.identity);
		point.GetComponent<Point>().aimPos = vector3;
		point.GetComponent<Point>().color = Color.gray;
		point.GetComponent<Point>().radius = 0.05f;
		pointList.Add(point);
	}

	private void AddPoint(Vector3 vector3, float radius, Color color) {
		point = Instantiate(pointPrefab, vector3, Quaternion.identity);
		point.GetComponent<Point>().aimPos = vector3;
		point.GetComponent<Point>().color = color;
		point.GetComponent<Point>().radius = radius;
		pointList.Add(point);
	}
}
